package com.bawei.module_my.view.activity

import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.bawei.module_base.net.bean.wide.FindGiftRecordByUidBean
import com.bawei.module_base.ui.base.BaseActivity
import com.bawei.module_my.R
import com.bawei.module_my.databinding.ActivityGiftRecordByUidBinding
import com.bawei.module_my.view.adapter.GiftRecordByUidAdapter
import com.bawei.module_my.viewmodel.MyViewModel
import com.google.android.material.tabs.TabLayout


@Route(path = "/my/giftrecordbyuid_activity")
class GiftRecordByUidActivity : BaseActivity<MyViewModel, ActivityGiftRecordByUidBinding>() {
    val titleArr= mutableListOf<String>("我收到的","我送出的")
    override fun getLayout(): Int {
        return R.layout.activity_gift_record_by_uid
    }
    var type:Int=1
    var labsGiftArr= mutableListOf<FindGiftRecordByUidBean>()

    override fun initData() {
        titleArr.forEach{title->
            binding.tbGift.addTab(binding.tbGift.newTab().setText(title))
        }
        viewModel.getFindGiftRecordByUid(type,1,10)
        viewModel.dataFindGiftRecordByUid.observe(this){
            it.result.let {
                it1->
                if (it1 != null) {
                    labsGiftArr.clear()
                    labsGiftArr.addAll(it1)
                }
                binding.giftRv.adapter?.notifyDataSetChanged()
                  }
            binding.giftRv.adapter= GiftRecordByUidAdapter(this,R.layout.gift_item,labsGiftArr)
            val linearLayoutManager = LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)
            binding.giftRv.layoutManager=linearLayoutManager
            binding.tbGift.addOnTabSelectedListener(object :TabLayout.OnTabSelectedListener{
                override fun onTabSelected(tab: TabLayout.Tab?) {
                    if (tab != null) {
                        type=tab.position+1
                        viewModel.getFindGiftRecordByUid(type,1,10)
                    }
//                    setTab(tab)
                }

                override fun onTabUnselected(tab: TabLayout.Tab?) {

                }
                override fun onTabReselected(tab: TabLayout.Tab?) {

                }

            })
        }

    }


    override fun getViewModelClass(): Class<MyViewModel> {
        return MyViewModel::class.java
    }

}